@extends('admin.layouts.master')
@section('css')
<style>
    /*master引入后显示==会员管理*/
    .system_manage{
        background: #393F64;
    }
    /*搜索框所在的区域*/
    .main_header{
        float: left;
        margin-top: 8px;
        width:100%;
        height: 100px;
        line-height: 100px;

    }
    .main_header_search{
        float: left;
        width: 155px;
        position: relative;
    }
    .main_header_search input{
        border-radius:6px;
        width: 215px;
        height: 40px;
        margin-top: 30px;
        border: 0px solid;
    }
    /*.main_header_search input:hover{*/
    /*box-shadow: 0 8px 12px rgba(0,0,0,0.2);*/
    /*}*/

    /*.main_header_search input{*/
    /*padding-left:45px;*/
    /*font-size: 16px;*/
    /*color:#ccc;*/
    /*}*/
    /*================*/
    .main_header_add{
        float: right;
        width: 215px;
        height: 100px;
        line-height: 100px;
        text-align: right;

    }
    .add_box {
        float: right;
        width: 90px;
        height: 40px;
        margin-top: 20px;
        background: #fff;
        line-height: 40px;
        cursor: pointer;
        border-radius: 6px;
        margin-right:40px;
        box-shadow: 0 8px 12px rgba(0,0,0,0.2);
    }
    .add_box img{
        float:left;
        margin-top:6px;
        margin-left:6px;
        width: 28px;
        height: 28px;
        line-height: 40px;
    }
    .add_box span{
        float: left;
        font-size:18px;
        margin-left: 8px;
        color:  #24a7f6;
    }
    /*======主要内容区=====*/
    .main_form{
        float: left;
        width: 100%;
        height: 783px;
        background: #fff;
        border-radius: 10px;
        box-shadow: 0 8px 12px rgba(0,0,0,0.2);
    }
    .main_formlist{
        margin-top:30px;
    }
    .main_table{
        width: 94%;
        margin: 0 auto;
        border: 1px solid #B1B1B1;
    }
    .main_table tr{
        height: 15px;
        width: 100%;
    }
    .main_table tr th{
        text-align: center;
        line-height: 20px;
        height: 20px;
        font-size: 18px;
    }
    .main_table tr td{
        text-align: center;
    }
    /*======操作中的编辑与删除的样式======*/
    .formlist_handle a{
        font-size:18px;
        text-decoration: none;
    }
    .formlist_handle span{
        font-size:18px;
        cursor: pointer;
    }
    .formlist_edit{
        color: #79C9F7;
    }
    .formlist_destory{
        color: red;
    }

    /*laravel自带的分页样式*/
    .boot_fenye{
        margin: 0 auto;
        margin-top:2px;
        width: 94%;
        height: 55px;
    }
    .boot_page{
        float: right;

    }
    .boot_page_di{
        margin-left: 10px;
        float: left;
        text-align: right;
        font-size: 14px;
        height: 74px;
        line-height: 74px;

    }
    .boot_page_di_span{
        width: 34px;
        height: 34px;
        border: 1px solid #D6D6D1;
    }
    .boot_page_total{
        margin-left: 10px;
        float:left;
        text-align: right;
        font-size: 14px;
        height: 74px;
        line-height: 74px;


    }
    .boot_choose{
        margin-left:20px;
        float:right;
    }
    .current_btn{
        background-color: white
    }
    .nocurrent_btn{
        background-color:rgba(0,0,0,0);
        color:white;
        border-color: white;
        border:1;
    }
</style>
@endsection
@section('content')

<div class="main_header clearfix">
    @if(Auth::guard('admin')->user()->checkPermission('user.list')) <button style="" class="btn current_btn" onclick="javascript:location.href = '/admin/user';">账号管理</button> @endif
    @if(Auth::guard('admin')->user()->checkPermission('role.list')) <button style="margin-left: 20px" class="btn nocurrent_btn" onclick="javascript:location.href = '/admin/role';">角色管理</button> @endif
</div>
<div  class="main_form clearfix">
    <form style="margin-left:40px;margin-top: 20px;float:left;" action="{{url('admin/user')}}" method="get">
        <div class="input-group input_style"  style="width:200px;">
            <input type="text" class="form-control" placeholder="输入用户名" name="search" value="{{$search or ''}}" style="height: 40px;"/>
            <span class="input-group-btn">
                <button type="submit" class="btn btn-info btn-search glyphicon glyphicon-search" style="margin-top:-3px;background: #3FB2F7;height: 40px; "></button>
            </span>
        </div>
    </form>
    @if(Auth::guard('admin')->user()->checkPermission('user.create'))
    <div style="float: right;" onclick="javascript:location.href='/admin/user/create'" class="add_box">
        <img src="{{asset('images/add_icon.png')}}" alt="">
        <span>新增</span> 
    </div>
    @endif
    <div style="clear: both"></div>
    <!-- 表格 -->
    <div class="main_formlist">
        <table class="table table-bordered main_table">
            <tbody>
                <tr>
                    <th>用户名</th>
                    <th>姓名</th>
                    <th>角色</th>
                    <th>创建时间</th>
                    <th>更新时间</th>
                    <th @if(!Auth::guard('admin')->user()->checkPermission('user.edit')) && !Auth::guard('admin')->user()->checkPermission('user.destroy') && !Auth::guard('admin')->user()->isSuperAdmin()) style="display: none" @endif>操作</th>
                </tr>
                @foreach($users as $user)
                <tr>
                    <td>{{$user->user_name}}</td>
                    <td>{{$user->name}}</td>
                    <td>{{implode(',',$user->roles->pluck('name')->toArray())}}</td>
                    <td>{{$user->created_at}}</td>
                    <td>{{$user->updated_at}}</td>
                    <td>
                        <span class="formlist_handle">
                            @if(Auth::guard('admin')->user()->checkPermission('user.edit'))
                            <a @if($user->id==1 && Auth::guard('admin')->user()->id!=1) style="display:none" @endif href="{{url('/admin/user/'.$user->id.'/edit')}}" class="formlist_edit">修改</a>&nbsp;&nbsp;&nbsp;&nbsp; 
                            @endif
                            @if(Auth::guard('admin')->user()->checkPermission('user.destroy')) 
                            <span @if($user->id==1 && Auth::guard('admin')->user()->id!=1) style="display:none" @endif class="formlist_destory remove" data-id="{{$user->id}}" >删除</span> 
                            @endif
                        </span>
                    </td>
                </tr>
                @endforeach
            </tbody>

        </table>
    </div>
    <div class="boot_fenye">
        <div class="boot_page">
            @if(isset($search))
            {{ $users->appends(['search' => $search])->links() }}
            @else
            {{ $users->links() }}
            @endif
        </div>
    </div>
</div>
@endsection
<!-- Modal -->
<div style="display: none;margin-top: 100px;" class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content" style="width: 350px;margin-left: 180px;">
            <div class="modal-header" style="background: #3D446B;">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close" style="color: white;"><span aria-hidden="true"><img
                            src="{{asset('/images/cancel_icon.png')}}" alt=""></span></button>
                <h4 class="modal-title" id="myModalLabel" style="color: white;text-align: center; font-size: 24px;">新增</h4>
            </div>
            <form id="addForm">
                <div class="modal-body">
                    <div class="modal_info clearfix">
                        <div class="form-group">
                            <label>用户名</label>
                            <input name="user_name" type="text" value="" class="form-control" required>
                            <div class="help-block with-errors"></div>
                        </div>
                        <div class="form-group">
                            <label>姓名</label>
                            <input name="name" type="text" value="" class="form-control" required>
                            <div class="help-block with-errors"></div>
                        </div>
                        <div class="form-group">
                            <label>密码</label>
                            <input id="password" name="password" type="password" value="" class="form-control" required>
                            <div class="help-block with-errors"></div>
                        </div>
                        <div class="form-group">
                            <label>确认密码</label>
                            <input data-match="#password" name="repassword" type="password" value="" class="form-control" required>
                            <div class="help-block with-errors"></div>
                        </div>
                        <div class="form-group">
                            <label>用户角色</label>
                            <div>
                                @foreach($roles as $role)
                                <div style="float: left;"><input name="roles[]" type="checkbox" value="{{$role->id}}">{{$role->name}}&nbsp;&nbsp;</div>
                                @endforeach
                                <div style="clear: both"></div>
                            </div>
                            <div class="help-block with-errors"></div>
                        </div>
                        <div style="padding-bottom:10px" class="form-group">
                            <label>备注</label>
                            <div>
                                <textarea name="remark" rows="10" value="" style="width: 100%"></textarea>
                            </div>
                        </div>
                    </div>
                </div>
                <div id="allmap" style="height:30%;display: none;"></div>
                <div class="modal-footer" style="text-align: center;">
                    <input type="submit" value="提交" class="btn btn-primary" style="height:40px;border: 0px solid;width: 300px;background: #2BAAF7" />
                </div>
            </form>
        </div>
    </div>
</div>
@section('js')
<script type="text/javascript">
    $(".remove").click(function () {
        var id = $(this).data('id');
        layer.confirm('确认删除?', {btn: ['是', '否']}, function () {
            layer.load(1, {shade: [0.1, '#fff']});
            $.ajax({
                url: "/admin/user" + '/' + id,
                type: 'delete',
                dataType: 'json',
                success: function (res) {
                    layer.closeAll();
                    if (res.status == 1) {
                        layer.msg(res.msg, {icon: 1});
                        //移除行
                        location.href = '/admin/user';
                    } else {
                        layer.msg(res.msg, {icon: 5});
                    }
                }
            });
        });
    });
    $('#addForm').validator().on('submit', function (e) {
        if (!e.isDefaultPrevented()) {
            layer.load(1, {shade: [0.1, '#fff']});
            $.ajax({
                url: "/admin/user",
                type: 'post',
                dataType: "json",
                data: $("#addForm").serialize(),
                success: function (res) {
                    layer.closeAll();
                    if (res.status == 1) {
                        layer.msg(res.msg, {icon: 1});
                        location.href = "/admin/user";
                    } else {
                        layer.msg(res.msg, {icon: 5});
                    }
                }
            });
        }
        return false;
    })
</script>
@endsection


